This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Load the required libraries. If you don’t have them installed, please do by running install.packages()

library(plotly)
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(stringr)
library(reshape2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(readr)

Load the NMR binned csv. Just adapt the path to location of your file. You can use autocompletion using the tab key

Binning_Fusarium_sh1 <- read_csv("../../data/Binning_Fusarium_matz_center.csv")
## Warning: Duplicated column names deduplicated: '-115.03' => '-115.03_1' [146],
## '702.028' => '702.028_1' [283], '1675.59' => '1675.59_1' [286],
## '-314.082' => '-314.082_1' [308], '-402.228' => '-402.228_1' [326],
## '-202.469' => '-202.469_1' [331], '-240.71' => '-240.71_1' [495],
## '313.821' => '313.821_1' [599], '443.177' => '443.177_1' [614],
## '-168.964' => '-168.964_1' [628], '-161.33' => '-161.33_1' [637],
## '-305.105' => '-305.105_1' [661], '65.8555' => '65.8555_1' [730],
## '281.871' => '281.871_1' [735], '785.014' => '785.014_1' [778], '221.152'
## => '221.152_1' [803], '141.064' => '141.064_1' [830], '-195.684' =>
## '-195.684_1' [865], '146.084' => '146.084_1' [874], '-49.4336' =>
## '-49.4336_1' [877], '96.0381' => '96.0381_1' [903], '-4.61914' =>
## '-4.61914_1' [921], '-40.5273' => '-40.5273_1' [923], '-57.3506' =>
## '-57.3506_1' [963], '-77.3545' => '-77.3545_1' [965], '-135.034' =>
## '-135.034_1' [982], '-121.533' => '-121.533_1' [986], '-135.883' =>
## '-135.883_1' [1002], '-168.964' => '-168.964_2' [1039], '-21.3008'
## => '-21.3008_1' [1041], '11.0029' => '11.0029_1' [1055], '134.562'
## => '134.562_1' [1058], '-200.207' => '-200.207_1' [1066], '52.9902'
## => '52.9902_1' [1077], '58.3623' => '58.3623_1' [1099], '-0.519531'
## => '-0.519531_1' [1131], '-130.652' => '-130.652_1' [1138], '158.453'
## => '158.453_1' [1140], '166.3' => '166.3_1' [1153], '92.4326' =>
## '92.4326_1' [1156], '-10.7686' => '-10.7686_1' [1160], '-36.7812'
## => '-36.7812_1' [1166], '131.098' => '131.098_1' [1174], '-150.373'
## => '-150.373_1' [1179], '149.265' => '149.265_1' [1190], '47.6885'
## => '47.6885_1' [1216], '10.7197' => '10.7197_1' [1225], '-60.6729'
## => '-60.6729_1' [1232], '-268.419' => '-268.419_1' [1236], '24.998'
## => '24.998_1' [1253], '-96.9346' => '-96.9346_1' [1264], '207.086'
## => '207.086_1' [1265], '-87.4629' => '-87.4629_1' [1276], '105.51'
## => '105.51_1' [1285], '50.2334' => '50.2334_1' [1288], '56.2412' =>
## '56.2412_1' [1293], '-26.1777' => '-26.1777_1' [1314], '-229.471'
## => '-229.471_1' [1318], '70.3086' => '70.3086_1' [1333], '-63.8535'
## => '-63.8535_1' [1342], '28.8857' => '28.8857_1' [1343], '86.5664'
## => '86.5664_1' [1345], '8.95312' => '8.95312_1' [1353], '43.8008'
## => '43.8008_1' [1354], '-5.4668' => '-5.4668_1' [1355], '-4.61914'
## => '-4.61914_2' [1361], '62.6035' => '62.6035_1' [1388], '75.8213'
## => '75.8213_1' [1395], '-67.2471' => '-67.2471_1' [1400], '22.666'
## => '22.666_1' [1410], '104.309' => '104.309_1' [1414], '19.9795' =>
## '19.9795_1' [1425], '26.3418' => '26.3418_1' [1428], '-10.415' =>
## '-10.415_1' [1431], '-75.5879' => '-75.5879_1' [1440], '-55.584' =>
## '-55.584_1' [1441], '4.64062' => '4.64062_1' [1444], '52.9902' =>
## '52.9902_2' [1456], '-85.625' => '-85.625_1' [1457], '-266.369' =>
## '-266.369_1' [1459], '-126.199' => '-126.199_1' [1472], '65.502' =>
## '65.502_1' [1506], '-126.128' => '-126.128_1' [1508], '-74.7393' =>
## '-74.7393_1' [1523], '-8.29492' => '-8.29492_1' [1540], '-82.0908'
## => '-82.0908_1' [1544], '-103.721' => '-103.721_1' [1554], '-19.958'
## => '-19.958_1' [1558], '18.3545' => '18.3545_1' [1572], '-116.373' =>
## '-116.373_1' [1578], '827.072' => '827.072_1' [1602]
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   .default = col_double()
## )
## ℹ Use `spec()` for the full column specifications.

Lets have a look at the first rows of this file

head(Binning_Fusarium_sh1)

OK. Be sure to have ppm on the columns and fraction numbers as rows. Now we transform the dataframe as a matrix

DTz <- as.matrix(data.frame(Binning_Fusarium_sh1))

Lets have a look at the structure of the file

str(DTz)
##  num [1:134, 1:1602] -12215 -13266 -12792 -12116 -12881 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr [1:1602] "X.14393.5" "X358.495" "X.14208.8" "X602.433" ...

Now we’ll remove the row indexes

DTz <- DTz[,-1] 

And we set the matrix row and colnames according to the ones of the df

colnames(DTz) <- colnames(Binning_Fusarium_sh1)[-1]
rownames(DTz) <- rownames(Binning_Fusarium_sh1)

Let’s transform these data in the long form

mtrx.melt <- melt(DTz, id.vars = c('sample', 'ppm'), measure.vars = 'int')
names(mtrx.melt) <- c('sample', 'ppm', 'int')

Now we can plot a quick 3Dplot to have an overview of the data

p <- plot_ly(z = ~DTz) %>% add_surface()

p

OK so now we want to remove the annoying signals corresponding to the solvents. We can check at the colunms name and note their numbers. Example its DMSO > signals at 2.5 ppm I want to delete columns 350,351 and 352.

colnames(DTz)
##    [1] "358.495"     "-14208.8"    "602.433"     "-953.72"     "-696.635"   
##    [6] "-713.104"    "-655.849"    "-586.647"    "-556.252"    "-456.443"   
##   [11] "-367.592"    "-187.201"    "-35.2256"    "14.4658"     "-106.619"   
##   [16] "358.354"     "129.261"     "339.622"     "187.93"      "383.023"    
##   [21] "424.374"     "402.179"     "342.52"      "118.799"     "165.169"    
##   [26] "534.361"     "473.147"     "100.421"     "379.064"     "231.26"     
##   [31] "382.67"      "390.162"     "368.179"     "527.223"     "493.435"    
##   [36] "601.23"      "27.0488"     "401.118"     "463.322"     "272.895"    
##   [41] "454.628"     "358.637"     "478.591"     "144.246"     "303.572"    
##   [46] "444.52"      "131.098"     "138.874"     "215.568"     "112.366"    
##   [51] "222.071"     "175.843"     "208.217"     "67.127"      "175.983"    
##   [56] "276.287"     "389.385"     "260.807"     "153.576"     "134.562"    
##   [61] "65.8555"     "200.229"     "341.389"     "118.092"     "416.599"    
##   [66] "213.659"     "-26.1777"    "-19.4629"    "215.427"     "214.296"    
##   [71] "81.4766"     "-25.4717"    "55.8174"     "-95.0967"    "138.096"    
##   [76] "81.6182"     "313.821"     "35.248"      "64.0176"     "3.50977"    
##   [81] "182.274"     "8.1748"      "187.223"     "74.1963"     "26.9072"    
##   [86] "160.928"     "139.651"     "-67.5293"    "85.2227"     "134.42"     
##   [91] "129.967"     "-126.199"    "-7.58789"    "-163.804"    "235.36"     
##   [96] "15.8799"     "50.5166"     "98.3701"     "83.668"      "-37.6289"   
##  [101] "-328.148"    "-126.411"    "-33.1055"    "-112.839"    "-40.5273"   
##  [106] "22.3125"     "-103.297"    "43.8008"     "-217.879"    "75.1855"    
##  [111] "-106.76"     "-161.188"    "10.5781"     "-190.24"     "-218.444"   
##  [116] "-10.9102"    "12.1338"     "-67.1055"    "-1.93262"    "-115.03"    
##  [121] "-182.677"    "-282.697"    "-295.421"    "-29.2178"    "-137.509"   
##  [126] "-132.561"    "-177.022"    "-5.4668"     "-43.3545"    "-114.96"    
##  [131] "-135.388"    "-185.434"    "7.18555"     "-188.968"    "-176.244"   
##  [136] "-231.309"    "-255.201"    "-148.183"    "-16.4941"    "-171.367"   
##  [141] "-18.6855"    "-222.402"    "-103.014"    "-202.469"    "-115.03_1"  
##  [146] "-161.684"    "-252.373"    "-80.1826"    "-398.481"    "-320.231"   
##  [151] "-280.789"    "-390.141"    "-185.646"    "-305.105"    "-216.041"   
##  [156] "-293.229"    "-293.583"    "-201.196"    "-419.97"     "-213.354"   
##  [161] "16.5166"     "-260.573"    "-82.2324"    "-274.074"    "-260.36"    
##  [166] "-207.912"    "-412.053"    "-361.725"    "-345.679"    "-240.71"    
##  [171] "-237.671"    "-270.964"    "-179.284"    "-402.228"    "-68.3066"   
##  [176] "-473.055"    "-346.881"    "-147.546"    "-222.897"    "-375.014"   
##  [181] "-325.392"    "-122.17"     "-234.631"    "-163.168"    "16.1631"    
##  [186] "-125.28"     "-62.1572"    "37.0146"     "238.611"     "240.449"    
##  [191] "220.375"     "-268.419"    "-364.976"    "-150.373"    "-301.005"   
##  [196] "-95.6621"    "26.3418"     "-14.0205"    "-138.145"    "11.2852"    
##  [201] "207.086"     "-256.332"    "-63.8535"    "-296.905"    "224.263"    
##  [206] "1341.88"     "548.146"     "5301.35"     "5063.42"     "504.744"    
##  [211] "785.014"     "1032.34"     "2084.08"     "1927.37"     "1625.75"    
##  [216] "2876.54"     "3343.21"     "2368.95"     "942.149"     "435.189"    
##  [221] "449.114"     "456.819"     "425.646"     "1371.99"     "3039.19"    
##  [226] "1787.41"     "3315.29"     "5336.48"     "2003.22"     "1695.31"    
##  [231] "933.172"     "1047.54"     "536.199"     "371.431"     "388.678"    
##  [236] "87.6973"     "-13.9492"    "394.757"     "576.915"     "44.3662"    
##  [241] "-174.194"    "141.56"      "4278.17"     "-44.1328"    "-158.715"   
##  [246] "-246.365"    "-195.612"    "58.2207"     "-113.829"    "-77.3545"   
##  [251] "15.0322"     "264.482"     "160.786"     "177.397"     "336.724"    
##  [256] "116.184"     "186.728"     "-200.065"    "-396.148"    "-254.564"   
##  [261] "-195.4"      "173.156"     "-237.176"    "-279.729"    "-324.826"   
##  [266] "-101.529"    "212.316"     "48.5371"     "-82.0908"    "-22.7852"   
##  [271] "-255.13"     "-368.581"    "-30.9141"    "-538.935"    "-279.517"   
##  [276] "-169.388"    "-275.629"    "-353.808"    "-3.7002"     "42.8115"    
##  [281] "702.028"     "702.028_1"   "443.177"     "1675.59"     "1675.59_1"  
##  [286] "3295.85"     "876.341"     "582.146"     "104.309"     "82.6074"    
##  [291] "-288.211"    "-133.196"    "-173.982"    "-404.065"    "-125.351"   
##  [296] "-367.309"    "-435.662"    "-228.835"    "-196.249"    "-209.325"   
##  [301] "-294.714"    "1009.94"     "-382.931"    "674.249"     "-253.363"   
##  [306] "-314.082"    "-314.082_1"  "-392.826"    "-453.687"    "-438.772"   
##  [311] "-55.3711"    "205.106"     "-313.375"    "102.965"     "-49.4336"   
##  [316] "-21.3008"    "-333.238"    "-133.55"     "-625.312"    "-491.15"    
##  [321] "-492.493"    "-322.776"    "-440.539"    "-321.504"    "-402.228_1" 
##  [326] "-431.916"    "-122.735"    "-474.186"    "-516.88"     "-202.469_1" 
##  [331] "-203.741"    "-32.3281"    "539.31"      "-479.487"    "20389"      
##  [336] "613.671"     "1259.53"     "-1378.61"    "-415.729"    "460.07"     
##  [341] "1321.87"     "45321.9"     "43390.2"     "5332.88"     "10040.9"    
##  [346] "28657.8"     "19250.2"     "8769"        "8787.37"     "14597.5"    
##  [351] "29674.7"     "102524"      "757484"      "1.90E+07"    "1.18E+06"   
##  [356] "243020"      "51894.9"     "31236"       "16133.4"     "10413.5"    
##  [361] "9314.48"     "12067.1"     "2887.78"     "4589.76"     "94192.6"    
##  [366] "23062.5"     "3709.29"     "2056.02"     "2069.94"     "2199.86"    
##  [371] "466.433"     "978.765"     "1028.95"     "1126.99"     "497.888"    
##  [376] "511.247"     "869.483"     "625.829"     "810.391"     "960.527"    
##  [381] "804.382"     "1169.62"     "986.822"     "234.865"     "547.227"    
##  [386] "166.3"       "220.233"     "201.147"     "244.974"     "202.208"    
##  [391] "175.206"     "122.051"     "354.749"     "-44.2734"    "187.294"    
##  [396] "49.8096"     "2.37891"     "320.042"     "1342.58"     "8941.33"    
##  [401] "374.541"     "237.41"      "29.0273"     "445.722"     "566.807"    
##  [406] "453.779"     "519.164"     "454.274"     "678.49"      "496.615"    
##  [411] "1070.02"     "583.135"     "1236.49"     "2219.8"      "7940.13"    
##  [416] "4900.78"     "965.192"     "1429.6"      "1358.49"     "2152.93"    
##  [421] "4612.59"     "1993.96"     "1921.15"     "2810.38"     "3361.09"    
##  [426] "4272.38"     "5766.89"     "5625.09"     "8655.61"     "12033.3"    
##  [431] "20393"       "33175.1"     "61905.3"     "152525"      "1.02E+06"   
##  [436] "1.46E+06"    "166382"      "60913.6"     "35899.1"     "21488.9"    
##  [441] "14860.4"     "10017.4"     "8240.55"     "6283.18"     "6664.39"    
##  [446] "5805.91"     "4730.49"     "3903.4"      "3366.47"     "3749.51"    
##  [451] "6450.78"     "9137.55"     "7284.45"     "4554.34"     "3685.05"    
##  [456] "3187.7"      "4872.08"     "4623.83"     "5808.74"     "4348.36"    
##  [461] "3160.49"     "3705.55"     "3552.3"      "4774.6"      "4690.84"    
##  [466] "3299.1"      "2635.29"     "2124.16"     "3312.32"     "2817.24"    
##  [471] "2975.64"     "2190.11"     "1752.49"     "1780.2"      "1352.62"    
##  [476] "2181.84"     "1490.81"     "2415.25"     "1979.75"     "2486.85"    
##  [481] "1079.7"      "928.224"     "635.584"     "645.621"     "294.029"    
##  [486] "1018.91"     "3302.57"     "1729.1"      "528.989"     "92.4326"    
##  [491] "309.792"     "591.971"     "180.225"     "-240.71_1"   "147.709"    
##  [496] "213.589"     "-230.249"    "420.91"      "4956.76"     "2161.48"    
##  [501] "170.471"     "15.7383"     "5.91309"     "1053.2"      "2762.24"    
##  [506] "1944.41"     "212.67"      "-65.9746"    "-134.822"    "-144.012"   
##  [511] "281.871"     "1071.93"     "662.232"     "285.052"     "52.4951"    
##  [516] "971.555"     "2295.57"     "1846.15"     "0.258789"    "-119.342"   
##  [521] "76.2461"     "649.438"     "1358.14"     "358.849"     "58.3623"    
##  [526] "-59.1885"    "-59.9658"    "57.8672"     "86.7783"     "216.486"    
##  [531] "180.437"     "-141.325"    "239.46"      "519.729"     "746.844"    
##  [536] "585.68"      "743.451"     "870.05"      "1033.69"     "3647.23"    
##  [541] "6732.18"     "4759.83"     "1569.49"     "1024.22"     "811.31"     
##  [546] "827.991"     "1163.33"     "3082.59"     "3521.62"     "895.214"    
##  [551] "509.339"     "689.8"       "150.325"     "96.0381"     "310.711"    
##  [556] "232.815"     "400.978"     "132.653"     "18.9199"     "-34.8018"   
##  [561] "141.064"     "656.295"     "690.719"     "1531.81"     "1279.82"    
##  [566] "409.035"     "524.466"     "208.57"      "946.531"     "2024.78"    
##  [571] "3222.97"     "2476.95"     "258.403"     "152.304"     "44.6494"    
##  [576] "186.516"     "154.354"     "225.464"     "143.468"     "148.981"    
##  [581] "261.584"     "-4.61914"    "169.764"     "341.247"     "600.1"      
##  [586] "601.867"     "221.152"     "19.7676"     "172.308"     "-180.839"   
##  [591] "-49.0098"    "-268.489"    "-252.444"    "213.377"     "-160.34"    
##  [596] "-402.439"    "-53.3926"    "313.821_1"   "-56.502"     "-38.4072"   
##  [601] "-135.883"    "-456.797"    "-132.277"    "-95.0264"    "-185.01"    
##  [606] "116.325"     "187.081"     "115.83"      "103.318"     "2187.71"    
##  [611] "4368.23"     "986.187"     "443.177_1"   "329.867"     "97.2393"    
##  [616] "-168.964"    "91.0898"     "29.8047"     "560.939"     "1628.58"    
##  [621] "307.601"     "-264.814"    "-161.33"     "-36.4277"    "-116.373"   
##  [626] "696.232"     "-168.964_1"  "-129.309"    "-427.745"    "-324.332"   
##  [631] "-98.7021"    "56.2412"     "-150.586"    "-101.741"    "-227.562"   
##  [636] "-161.33_1"   "-242.194"    "-195.684"    "1742.31"     "1608.15"    
##  [641] "716.52"      "1171.03"     "2055.81"     "1557.68"     "1317.7"     
##  [646] "8813.17"     "2267.93"     "-130.652"    "-333.874"    "-376.215"   
##  [651] "-273.791"    "-407.67"     "-413.396"    "-656.344"    "-491.574"   
##  [656] "-314.647"    "-120.049"    "-245.658"    "-317.546"    "-305.105_1" 
##  [661] "-382.012"    "-447.184"    "-126.128"    "-187.413"    "8.74023"    
##  [666] "-158.148"    "998.769"     "-20.3115"    "-374.165"    "-456.655"   
##  [671] "-266.369"    "-39.3965"    "-307.861"    "-252.091"    "-302.207"   
##  [676] "-212.365"    "-172.64"     "-139.771"    "415.256"     "1755.18"    
##  [681] "565.676"     "-154.261"    "-55.8662"    "-305.953"    "-526.564"   
##  [686] "-29.4297"    "-525.646"    "-156.877"    "2170.53"     "2577.54"    
##  [691] "-167.268"    "-336.984"    "-199.712"    "-367.662"    "-478.427"   
##  [696] "-370.772"    "-534.552"    "-194.481"    "-389.857"    "-419.334"   
##  [701] "-210.244"    "-200.207"    "-212.224"    "47.6885"     "-432.41"    
##  [706] "-296.41"     "-337.126"    "-198.864"    "-268.914"    "-148.253"   
##  [711] "-381.021"    "-215.829"    "-283.192"    "-67.0342"    "38.0049"    
##  [716] "25.7764"     "-212.082"    "-110.224"    "11.0029"     "-355.504"   
##  [721] "81.123"      "-232.652"    "-346.668"    "-149.879"    "-152.282"   
##  [726] "173.58"      "-36.71"      "99.7842"     "65.8555_1"   "190.828"    
##  [731] "454.84"      "162.129"     "38.5703"     "281.871_1"   "-93.4717"   
##  [736] "457.313"     "555.002"     "708.603"     "417.729"     "187.718"    
##  [741] "305.057"     "158.312"     "-72.9014"    "23.5137"     "157.817"    
##  [746] "290"         "441.551"     "1382.1"      "175.277"     "224.05"     
##  [751] "461.838"     "494.354"     "152.516"     "217.265"     "381.326"    
##  [756] "682.236"     "370.865"     "422.042"     "17.7881"     "64.9365"    
##  [761] "283.073"     "137.46"      "289.576"     "176.479"     "164.108"    
##  [766] "213.801"     "199.805"     "492.445"     "486.86"      "696.374"    
##  [771] "511.459"     "629.293"     "498.807"     "625.547"     "582.641"    
##  [776] "570.623"     "785.014_1"   "705.775"     "909.28"      "747.339"    
##  [781] "694.678"     "815.833"     "542.35"      "244.479"     "371.854"    
##  [786] "193.16"      "-51.2715"    "59.1396"     "-140.689"    "938.049"    
##  [791] "623.497"     "200.865"     "6.76172"     "105.51"      "348.245"    
##  [796] "264.978"     "258.475"     "39.3477"     "213.447"     "242.217"    
##  [801] "396.241"     "221.152_1"   "430.736"     "1800.98"     "432.361"    
##  [806] "181.215"     "281.518"     "736.947"     "473.854"     "623.709"    
##  [811] "1961.87"     "671.917"     "-57.2803"    "95.6143"     "100.986"    
##  [816] "58.4326"     "124.383"     "65.502"      "173.015"     "176.267"    
##  [821] "398.009"     "76.9531"     "21.6758"     "113.073"     "107.701"    
##  [826] "64.2295"     "50.2334"     "258.263"     "141.064_1"   "433.775"    
##  [831] "1577.19"     "1939.1"      "1895.99"     "2033.47"     "5548.68"    
##  [836] "1346.05"     "528.282"     "326.898"     "560.586"     "1979.89"    
##  [841] "10791.3"     "-50.4238"    "196.129"     "62.6035"     "77.165"     
##  [846] "146.084"     "-264.531"    "-17.8369"    "-215.122"    "-24.835"    
##  [851] "-227.351"    "-229.471"    "-192.644"    "-113.617"    "-66.2568"   
##  [856] "-128.743"    "-339.883"    "-117.575"    "-141.396"    "-1.5791"    
##  [861] "-34.166"     "18.4248"     "-185.504"    "-195.684_1"  "86.5664"    
##  [866] "-154.12"     "149.265"     "-13.3135"    "50.7285"     "124.171"    
##  [871] "-99.4795"    "-15.0098"    "146.084_1"   "-154.474"    "-60.6729"   
##  [876] "-49.4336_1"  "-70.8516"    "-62.6523"    "-172.286"    "-37.417"    
##  [881] "-173.417"    "-164.511"    "-362.644"    "-172.428"    "-204.519"   
##  [886] "-135.034"    "259.817"     "49.5264"     "1179.65"     "2135.05"    
##  [891] "241.58"      "21.3936"     "301.381"     "104.661"     "6.5498"     
##  [896] "201.431"     "410.661"     "648.802"     "388.748"     "223.556"    
##  [901] "282.437"     "96.0381_1"   "276.782"     "-100.61"     "-181.97"    
##  [906] "259.676"     "1392.14"     "243.56"      "359.626"     "379.913"    
##  [911] "1642.08"     "1792.15"     "1393.27"     "1327.32"     "1154.14"    
##  [916] "390.516"     "-2.56934"    "53.2725"     "-162.319"    "-4.61914_1" 
##  [921] "-104.993"    "-40.5273_1"  "79.0029"     "-179.496"    "72.8525"    
##  [926] "-136.448"    "-291.038"    "-8.50684"    "130.392"     "135.057"    
##  [931] "489.335"     "420.062"     "828.769"     "2038.56"     "6233.28"    
##  [936] "6566.77"     "1049.52"     "227.302"     "90.5947"     "-19.958"    
##  [941] "7.53906"     "-55.5127"    "-238.66"     "-195.117"    "-103.721"   
##  [946] "22.666"      "-16.5645"    "182.981"     "286.254"     "1721.75"    
##  [951] "1833.85"     "896.345"     "327.04"      "-130.723"    "128.129"    
##  [956] "-90.6436"    "-5.82031"    "-161.612"    "-57.3506"    "-75.5879"   
##  [961] "-249.334"    "-57.3506_1"  "-308.074"    "-77.3545_1"  "-302.843"   
##  [966] "-190.452"    "-260.502"    "-153.342"    "-63.7832"    "-109.163"   
##  [971] "-121.533"    "-381.799"    "-166.914"    "-390.847"    "-124.785"   
##  [976] "-96.0869"    "-111.284"    "-231.238"    "50.8691"     "-117.929"   
##  [981] "-135.034_1"  "-36.2861"    "-93.3301"    "-179.426"    "-121.533_1" 
##  [986] "-340.165"    "-302.631"    "-163.945"    "-70.0039"    "-117.292"   
##  [991] "-75.6582"    "-217.454"    "-221.13"     "-33.459"     "-68.3779"   
##  [996] "492.304"     "3623.2"      "216.346"     "-76.9307"    "-36.7812"   
## [1001] "-135.883_1"  "-47.3838"    "-126.835"    "-140.831"    "-305.317"   
## [1006] "-260.785"    "-49.3633"    "-94.8145"    "221.364"     "158.453"    
## [1011] "232.32"      "89.8887"     "-83.7168"    "111.589"     "9.51855"    
## [1016] "32.9863"     "-117.08"     "-38.8311"    "7.04395"     "-60.1074"   
## [1021] "-96.9346"    "-36.2158"    "-76.4355"    "14.1836"     "-250.253"   
## [1026] "18.001"      "-108.527"    "-211.588"    "-301.5"      "38.4287"    
## [1031] "-148.96"     "28.8857"     "-21.6543"    "-346.739"    "-115.667"   
## [1036] "-49.8584"    "-142.81"     "-168.964_2"  "89.4639"     "-21.3008_1" 
## [1041] "206.379"     "-344.124"    "-144.153"    "-98.3486"    "-229.33"    
## [1046] "-192.148"    "-140.901"    "-185.787"    "-62.5107"    "-142.174"   
## [1051] "-19.3926"    "4.64062"     "52.9902"     "11.0029_1"   "-168.894"   
## [1056] "-239.721"    "134.562_1"   "-156.594"    "-218.656"    "-86.8271"   
## [1061] "40.9736"     "-83.3633"    "-58.9766"    "-175.538"    "-200.207_1" 
## [1066] "-108.386"    "71.0146"     "197.331"     "-1.36719"    "250.84"     
## [1071] "104.521"     "94.9072"     "-39.6084"    "8.95312"     "19.9795"    
## [1076] "52.9902_1"   "-354.02"     "-5.8916"     "-223.745"    "-57.1387"   
## [1081] "-59.6123"    "-245.163"    "-14.9395"    "-53.6748"    "-14.5859"   
## [1086] "26.4824"     "-184.02"     "125.302"     "64.2998"     "-182.182"   
## [1091] "-83.4336"    "209.63"      "-166.702"    "124.595"     "-110.931"   
## [1096] "11.71"       "-169.671"    "58.3623_1"   "-55.1592"    "165.311"    
## [1101] "-53.8164"    "51.3643"     "-7.23438"    "-181.334"    "80.5576"    
## [1106] "-123.654"    "-184.585"    "10.7197"     "-153.979"    "-176.456"   
## [1111] "18.3545"     "-28.2285"    "-12.1826"    "-69.0137"    "109.539"    
## [1116] "-115.102"    "70.3086"     "-8.43555"    "14.749"      "78.2959"    
## [1121] "713.197"     "-119.555"    "-10.7686"    "-37.5586"    "-154.686"   
## [1126] "-0.519531"   "-115.737"    "-10.415"     "-140.548"    "-0.519531_1"
## [1131] "8.88184"     "-107.962"    "-19.6045"    "117.668"     "-92.623"    
## [1136] "104.025"     "-130.652_1"  "13.123"      "158.453_1"   "-272.377"   
## [1141] "29.9463"     "-117.505"    "137.248"     "10.1543"     "294.241"    
## [1146] "-214.627"    "103.39"      "142.974"     "-20.7354"    "-46.3232"   
## [1151] "77.7305"     "166.3_1"     "111.659"     "3.86328"     "92.4326_1"  
## [1156] "37.793"      "-144.719"    "45.4268"     "-10.7686_1"  "-95.8037"   
## [1161] "9.23535"     "41.8926"     "18.1416"     "151.95"      "-36.7812_1" 
## [1166] "138.661"     "-57.4922"    "60.624"      "-9.70801"    "142.055"    
## [1171] "-128.603"    "-16.9893"    "131.098_1"   "-245.517"    "-38.6895"   
## [1176] "46.6279"     "-197.097"    "-150.373_1"  "74.3369"     "205.389"    
## [1181] "106.287"     "171.46"      "186.304"     "141.277"     "136.541"    
## [1186] "139.156"     "314.882"     "-58.2695"    "149.265_1"   "387.9"      
## [1191] "-67.7412"    "311.418"     "147.639"     "115.972"     "15.3848"    
## [1196] "254.304"     "76.5996"     "471.663"     "121.768"     "193.09"     
## [1201] "88.6162"     "323.576"     "34.9648"     "310.146"     "97.0273"    
## [1206] "243.206"     "75.8213"     "214.225"     "-27.3096"    "112.578"    
## [1211] "115.547"     "159.231"     "-63.0059"    "195.281"     "47.6885_1"  
## [1216] "225.747"     "135.834"     "217.193"     "170.399"     "-107.043"   
## [1221] "-5.11328"    "-145.354"    "24.998"      "10.7197_1"   "-79.8994"   
## [1226] "92.8574"     "-39.5381"    "37.0859"     "-188.402"    "-87.4629"   
## [1231] "-60.6729_1"  "162.624"     "100.067"     "101.269"     "-268.419_1" 
## [1236] "274.379"     "-165.006"    "53.5557"     "-124.361"    "-110.012"   
## [1241] "-129.662"    "-27.7334"    "-11.1924"    "-85.625"     "126.716"    
## [1246] "-2.70996"    "-33.8125"    "216.699"     "153.859"     "54.0508"    
## [1251] "110.175"     "24.998_1"    "-213.566"    "79.7803"     "-50.918"    
## [1256] "87.4141"     "-259.159"    "-90.4316"    "9.30664"     "43.5186"    
## [1261] "-30.1367"    "-117.222"    "-96.9346_1"  "207.086_1"   "-74.7393"   
## [1266] "331.352"     "-158.927"    "47.5469"     "69.8838"     "35.9551"    
## [1271] "-99.4092"    "-4.97266"    "108.62"      "15.668"      "-87.4629_1" 
## [1276] "161.493"     "125.231"     "-73.3262"    "51.1523"     "-68.0244"   
## [1281] "170.683"     "198.462"     "-148.395"    "105.51_1"    "-8.71875"   
## [1286] "17.4355"     "50.2334_1"   "-5.67969"    "74.4082"     "-26.6729"   
## [1291] "82.3252"     "56.2412_1"   "144.6"       "-48.9395"    "-83.5049"   
## [1296] "-123.159"    "59.3516"     "-29.7832"    "-8.29492"    "37.8633"    
## [1301] "229.988"     "-152.353"    "-11.334"     "-132.702"    "-147.616"   
## [1306] "-62.0156"    "-165.218"    "-189.887"    "-63.7129"    "-8.01172"   
## [1311] "-29.9248"    "-124.502"    "-26.1777_1"  "-8.36523"    "152.587"    
## [1316] "-49.6455"    "-229.471_1"  "-23.9873"    "102.188"     "151.103"    
## [1321] "60.6953"     "94.4121"     "-29.5"       "-15.2217"    "-90.5732"   
## [1326] "317.214"     "-16.0703"    "-127.896"    "29.4521"     "36.8027"    
## [1331] "-87.6748"    "70.3086_1"   "-58.4111"    "-255.767"    "-27.9453"   
## [1336] "179.871"     "-172.003"    "-20.5938"    "85.9297"     "-16.1406"   
## [1341] "-63.8535_1"  "28.8857_1"   "127.352"     "86.5664_1"   "-27.0264"   
## [1346] "136.823"     "-94.1074"    "163.261"     "-5.39648"    "202.773"    
## [1351] "-57.209"     "8.95312_1"   "43.8008_1"   "-5.4668_1"   "4.28711"    
## [1356] "127.069"     "-57.8457"    "-228.27"     "84.7285"     "-4.61914_2" 
## [1361] "-161.118"    "92.0088"     "-53.0391"    "-9.35449"    "-111.496"   
## [1366] "-55.584"     "246.74"      "146.79"      "-143.234"    "204.117"    
## [1371] "-150.091"    "-0.166016"   "247.73"      "-93.8242"    "72.1465"    
## [1376] "277.913"     "44.5078"     "-38.4775"    "-81.9492"    "67.4102"    
## [1381] "70.0254"     "-180.769"    "91.8672"     "2.80273"     "38.2168"    
## [1386] "-15.1514"    "62.6035_1"   "18.6367"     "39.7715"     "-99.1963"   
## [1391] "-104.781"    "-30.2783"    "-90.0781"    "75.8213_1"   "-173.771"   
## [1396] "-67.2471"    "52.2832"     "-43.6377"    "-67.2471_1"  "136.895"    
## [1401] "3.79297"     "198.392"     "41.6094"     "-78.3447"    "-44.7686"   
## [1406] "-128.673"    "86.1416"     "222.919"     "22.666_1"    "176.055"    
## [1411] "-231.592"    "-169.6"      "104.309_1"   "-190.028"    "-0.873047"  
## [1416] "-45.8994"    "-96.793"     "12.8408"     "108.974"     "-25.9658"   
## [1421] "28.25"       "278.62"      "98.583"      "19.9795_1"   "29.5928"    
## [1426] "-43.7793"    "26.3418_1"   "-47.8076"    "75.6094"     "-10.415_1"  
## [1431] "72.2168"     "178.528"     "80.3457"     "-56.29"      "-80.041"    
## [1436] "76.1748"     "33.3398"     "-50.5645"    "-75.5879_1"  "-55.584_1"  
## [1441] "-10.9805"    "-90.29"      "4.64062_1"   "-95.168"     "145.519"    
## [1446] "71.7217"     "-38.0537"    "-28.5107"    "276.499"     "51.0107"    
## [1451] "28.8154"     "-207.629"    "-26.3906"    "76.458"      "52.9902_2"  
## [1456] "-85.625_1"   "-82.0205"    "-266.369_1"  "-4.68945"    "-97.0059"   
## [1461] "385.851"     "-33.8828"    "-72.4072"    "22.3828"     "168.067"    
## [1466] "98.8652"     "8.03418"     "-16.7061"    "-107.82"     "90.9482"    
## [1471] "-126.199_1"  "-80.8184"    "18.2129"     "89.3936"     "64.6533"    
## [1476] "194.856"     "-196.178"    "204.965"     "-16.918"     "-67.6006"   
## [1481] "203.339"     "0.612305"    "-68.5195"    "-31.4092"    "30.4414"    
## [1486] "-104.852"    "-116.727"    "-3.34668"    "222.212"     "5.98438"    
## [1491] "132.017"     "-197.733"    "-87.0391"    "135.339"     "-101.671"   
## [1496] "19.626"      "-100.257"    "-73.9619"    "71.8633"     "59.5635"    
## [1501] "-38.3359"    "20.1211"     "-42.7891"    "-50.7773"    "65.502_1"   
## [1506] "-48.8682"    "-126.128_1"  "48.2539"     "-160.128"    "40.6201"    
## [1511] "-120.968"    "-213.991"    "191.817"     "-171.862"    "-79.4756"   
## [1516] "28.1797"     "45.9922"     "-199.642"    "-71.5586"    "-101.034"   
## [1521] "-47.5957"    "-74.7393_1"  "-91.916"     "-57.5625"    "-26.0371"   
## [1526] "66.1377"     "-91.6338"    "-98.207"     "-349.071"    "-174.548"   
## [1531] "-14.4443"    "-139.063"    "-169.741"    "-202.822"    "-41.1641"   
## [1536] "-90.3613"    "27.1191"     "-201.126"    "-8.29492_1"  "-61.2383"   
## [1541] "-64.0654"    "-304.61"     "-82.0908_1"  "-19.7461"    "3.43945"    
## [1546] "-155.18"     "-35.7207"    "-118.848"    "-210.174"    "-332.248"   
## [1551] "-192.997"    "-108.951"    "-103.721_1"  "-79.4043"    "-133.975"   
## [1556] "-117.434"    "-19.958_1"   "63.0986"     "-58.1279"    "-22.3613"   
## [1561] "-233.218"    "-100.469"    "-245.446"    "-170.802"    "116.537"    
## [1566] "-280.294"    "-154.544"    "-163.733"    "-197.238"    "-249.899"   
## [1571] "18.3545_1"   "-281.708"    "-169.317"    "-70.2861"    "-126.693"   
## [1576] "-92.7646"    "-116.373_1"  "-249.404"    "-28.1572"    "-15.9287"   
## [1581] "49.1025"     "-168.54"     "-82.7266"    "-136.59"     "45.7803"    
## [1586] "144.67"      "351.992"     "165.664"     "156.687"     "82.1123"    
## [1591] "72.3584"     "125.726"     "428.191"     "362.171"     "321.385"    
## [1596] "578.611"     "578.046"     "599.251"     "832.656"     "827.072"    
## [1601] "827.072_1"
DTzred <- DTz[,-348:-352]

Now lets plot again …. Does it looks better ?

p <- plot_ly(z = ~DTzred) %>% add_surface()

p

Else repeat the previous step For this execute the following code. Be sure to run it on the previously cleaned object. In this case DTzred Be sure to check again the columns numbers sinsce these have changed

colnames(DTzred)
DTzred <- DTzred[,-348:-352]

Now that you have the cleaned data object lets have a look at the 2d map. Be patient, this one is longer to plot.

p <- plot_ly(mtrx.melt, x = ~sample, y = ~ppm, z = ~int, type = "contour",
             colors = 'YlOrRd',
             autocontour = F,
             contours = list(
               start = 10000,
               end = 1200000,
               size = 5000
             )
            )

p

If you want to plot the map with ppm on the x-axis just reverse the axis order. Play with start value (to fix the noise) and size value to fix the contour space. Change color if you wish by changing the color field. For more info on 2d contour plot with plotly check https://plot.ly/r/contour-plots/

p <- plot_ly(mtrx.melt, x = ~ppm, y = ~sample, z = ~int, type = "contour",
             autocontour = F,
             colors = 'YlOrRd',
             contours = list(
               start = 10000,
               end = 1200000,
               size = 50000
             )
            ) %>% layout(xaxis = list(autorange = "reversed"))

p

When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Cmd+Shift+K to preview the HTML file).

The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.